package ui.activity.mine.biz;

import Bean.FindAddressBean;
import Bean.SetDefaultAddressBean;
import base.BaseBiz;
import base.BaseResp;
import coom.BaseSubscribe;
import coom.RetrofitHelp;
import okhttp3.RequestBody;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by chenjian on 19/2/26.
 * 1
 */

public class ManagerAddressBiz extends BaseBiz {

    /**
     * 获取地址列表列表
     */
    public void getAddressList(RequestBody requestBody, final Callback<FindAddressBean.DataBean> callback) {
        com.add(RetrofitHelp.getSecretApi().findAddressBuCustomId(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<FindAddressBean.DataBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((FindAddressBean.DataBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((FindAddressBean.DataBean) obj);
                    }
                })
        );
    }


    /**
     * 设置默认地址
     */
    public void setDefaultAddress(RequestBody requestBody, final Callback<SetDefaultAddressBean.DataBean> callback) {
        com.add(RetrofitHelp.getSecretApi().defaultaddress(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<SetDefaultAddressBean.DataBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((SetDefaultAddressBean.DataBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((SetDefaultAddressBean.DataBean) obj);
                    }
                })
        );
    }


    /**
     * 删除地址
     */
    public void deleteAddress(RequestBody requestBody, final Callback<Object> callback) {
        com.add(RetrofitHelp.getSecretApi().deleltAddress(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<Object>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Object) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Object) obj);
                    }
                })
        );
    }


}
